//
//  LSZMJViewController.m
//  ShipinModel
//
//  Created by mac on 2018/12/24.
//  Copyright © 2018 mac. All rights reserved.
//

#import "LSZMJViewController.h"
#import <MJRefresh.h>

//#import <>
@interface LSZMJViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableViewNew;
@property(nonatomic, strong)MJRefreshAutoNormalFooter *footer;

@property(nonatomic,assign) NSInteger mainPage;

@property(nonatomic,assign) NSInteger countData;
@end

@implementation LSZMJViewController
#pragma mark - foot上添加  没有数据的时候添加我是有底线的标识
- (void)viewDidLoad {
    [super viewDidLoad];
    self.countData = 10;
    [self.tableViewNew registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    self.tableViewNew.mj_footer = [self footer];
 
}

//上拉加载更多
-(MJRefreshAutoNormalFooter *)footer{
     if (!_footer) {
        //    上拉加载更多
        _footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
            self.mainPage++;
            [self moreData];
         }];
        [_footer setTitle:@"我是有底线的" forState:MJRefreshStateNoMoreData];
    }
    return _footer;
}
-(void)moreData
{
    if (self.mainPage >= 3) {
        self.countData = self.countData;
        [self.tableViewNew.mj_footer endRefreshingWithNoMoreData];
    }else{
        self.countData += 10;
    }
    [self.tableViewNew.mj_footer endRefreshing];
    [self.tableViewNew reloadData];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.countData;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 45;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    cell.textLabel.text = [NSString stringWithFormat:@"%ld",(long)indexPath.row];
    return cell;
    
}
 

@end
